package cz.muni.fi.pa165.machineryrental.converters;

import cz.muni.fi.pa165.machineryrental.dto.MachineDTO;
//import cz.muni.fi.pa165.machineryrental.dto.MachineDetailDTO;
import cz.muni.fi.pa165.machineryrental.entities.Machine;

/**
 *
 * @author Martin Klvana, 395893
 */
public class MachineDTOConverter {
    /**
     * Converts Machine entity to MachineDTO
     * @param entity
     * @return MachineDTO which is set by Machine entity 
     */
    public static MachineDTO toDTO(Machine entity) {
        if (entity == null) {
            throw new IllegalArgumentException("Entity can't be null.");
        }

        MachineDTO dto = new MachineDTO();
        MachineDTOConverter.applyToDTO(entity, dto);
        
        return dto;
    }
	
	/**
	 * Retuns given machine entity converted to dto with loaded revisions.
	 * @param entity Machine entity loaded from database.
	 * @return Machine dto with revisions list.
	 */
//	public static MachineDetailDTO toDetailDTO(Machine entity) {
//		
//		if (entity == null) {
//            throw new IllegalArgumentException("Entity can't be null.");
//        }
//		
//		
//		
//	}

    /**
     * Converts MachineDTO to Machine entity
     * @param dto
     * @return Machine entity which is set by MachineDTO
     */
    public static Machine toEntity(MachineDTO dto) {
        if (dto == null) {
            throw new IllegalArgumentException("dto can't be null.");
        }

        Machine entity = new Machine();
        entity.setId(dto.getId());
        entity.setBrand(dto.getBrand());
        entity.setCode(dto.getCode());
        entity.setModel(dto.getModel());
        entity.setYearOfProduction(dto.getYearOfProduction());

        return entity;
    }
	
	/**
	 * Converts machine entity to basic machine DTO
	 * @param entity Machine entity
	 * @param dto Machine dto
	 * @return Given modified machine dto.
	 */
	public static MachineDTO applyToDTO(Machine entity, MachineDTO dto) {
		
		dto.setId(entity.getId());
        dto.setBrand(entity.getBrand());
        dto.setCode(entity.getCode());
        dto.setModel(entity.getModel());
        dto.setYearOfProduction(entity.getYearOfProduction());
		
		return dto;
	}
}
